import '../../core/service_locator.dart';
import '../../models/cart_model.dart';
import '../../core/http_client.dart';

class CartService {
  final HttpClient _http = ServiceLocator.httpClient;

  Future<Cart> getCart() async {
    final response = await _http.get('/cart');
    return Cart.fromJson(response.data);
  }

  Future<Cart> addToCart(String productId, int quantity) async {
    final response = await _http.post(
      '/cart/items',
      data: {'productId': productId, 'quantity': quantity},
    );
    return Cart.fromJson(response.data);
  }

  Future<Cart> updateCartItem(String itemId, int quantity) async {
    final response = await _http.put(
      '/cart/items/$itemId',
      data: {'quantity': quantity},
    );
    return Cart.fromJson(response.data);
  }

  Future<void> removeCartItem(String itemId) async {
    await _http.delete('/cart/items/$itemId');
  }
}
